<?php
namespace app\mouth\controller;
use app\mouth\common\Api;
use app\mouth\model\ShopModel;
use think\Db;
use think\Controller;
/**
 * 首页
 * Class ShopApi
 * @package app\mouth\controller
 */
class ShopApi extends Api{
    public $b_id='';
    public $g_id='';
    public $s_id='';
    /**
     * 获取全部店铺
     * @return false|string
     */
    public function index(){
        $shop = (new ShopModel)->index($this->openid);
        return $this->jsons('40006','获取成功',$shop);
    }

    /**
     * 消息提示
     */
    public function remind(){
        return $this->jsons('40006','获取成功',(new ShopModel)->remindadd($this->openid));
    }
    /**
     * 车辆
     * 4  轮胎
     * 1  洗车
     * 3  喷漆
     */
    public function vehicleTires(){
        $vehicleuser = Db::name('vehicle_user')->where('openid',$this->openid)->find();
        if (empty($vehicleuser)){
            return $this->jsons('40003','请先添加车辆',[]);
        }
        $tires = ShopModel::cehicleCategory(input('category'));
        if ($tires === false){
            return $this->jsons('40003','数据为空',[]);
        }
        return $this->jsons('40006','获取成功',$tires);
    }

    /**
     * 排序
     */
    public function score(){
        $add = (new ShopModel)->score();
        echo '<pre>';
        var_dump($add);
    }


    /**
     * 店铺详情
     * @return false|string
     */
    public function shopDetails(){
        $ma_id = input('ma_id');
        if (!empty($ma_id)){
            $ma_name = (new ShopModel)->shopDetails($ma_id);
            if (!empty($ma_name)){
                return $this->jsons('40006','获取成功',$ma_name);
            }
            return $this->jsons('40003','店铺不存在');
        }
        return $this->jsons('40003','缺少参数');
    }

    /**
     * 用户选车
     * b_id  品牌
     * g_id  车系组
     * s_id  车系
     * i_id  车
     */
    public function carSelection(){
        $this->b_id = input('b_id');
        $this->g_id = input('g_id');
        $this->s_id = input('s_id');
        $vehicle = ShopModel::brand($this->b_id,$this->g_id,$this->s_id);
        return $this->jsons('40006','获取成功',$vehicle);
    }

    /**
     * 用户添加车辆
     * @return false|string
     */
    public function carSelections(){
//        var_dump(input());die;
        $vehicle = ShopModel::brands(input());
        return $this->add($vehicle);
    }

    /**
     * 用户所有车辆
     */
    public function allCars(){
        $add = ShopModel::allcars($this->openid);
        return $this->jsons('40006','成功',$add);
    }
    /**
     * 默认车辆
     */
    public function vehicleDefault(){
        $default = ShopModel::Silence($this->openid,input('id'));
        return $this->add($default);
    }
    /**
     * 删除车辆
     */
    public function vehicleDe(){
        $default = ShopModel::vehicleDe($this->openid,input('id'));
        return $this->add($default);
    }
    /**
     * 添加评论
     * @return false|string
     */
    public function shopReviews(){
        $reviews = ShopModel::reviews($this->openid,$this->portrait,$this->nickname,$this->user_id,input('ma_id'),input('comment'));
        if ($reviews === true){
            return $this->jsons('40006','成功',[]);
        } else {
            return $this->jsons('40003','失败',$reviews);
        }
}

}